﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _7_1_Class
{

    internal class Test
    {

    }

    public interface IGetArea
    {
        float GetArea();
    }

    public interface IGetArea2
    {
        float GetArea();
    }

    public abstract class BaseGraph //: IGetArea, IGetArea2
    {
        public enum E_GraphType
        {
            None,
            Rectangle,
            Triangle,
            Square,
        }

        protected E_GraphType GraphType = E_GraphType.None;

        public E_GraphType GetGraphType()
        {
            return GraphType;
        }
        public virtual float GetGirth()
        {
            return 0;
        }
        /*
        float IGetArea.GetArea()
        {
            return 0;
        }

        float IGetArea2.GetArea()
        {
            return 0;
        }
        */
        public abstract float GetArea();

        /*
        public float GetArea()
        {
            throw new NotImplementedException();
        }
        */

        /*
        public virtual float GetArea()
        {
            return 0;
        }
        */
    }

    public class Square : Rectangle
    {
        private float Width;
        public Square()
        {
            GraphType = E_GraphType.Square;
        }

        public Square(float a) : base(a,a)
        {
            GraphType = E_GraphType.Square;
            Width = a;
        }

        public float GetArea()
        {
            return Width*Width;
        }

        /*
        public override float GetArea()
        {
            return Width*Width;
        }
        */
        public override float GetGirth()
        {
            return base.GetGirth();
        }
    }

    //矩形
    public class Rectangle : BaseGraph
    {
        private float Width;
        private float Hight;
        public Rectangle()
        {
            GraphType = E_GraphType.Rectangle;
        }

        public Rectangle(float w, float h)
        {
            GraphType = E_GraphType.Rectangle;
            Width = w;
            Hight = h;
        }

        /*
        public override float GetArea()
        {
            return Width*Hight;
        }
        */
        public override float GetGirth()
        {
            return Width*2+Hight*2;
        }

        public override float GetArea()
        {
            return Width * Hight;
        }
    }

    //三角形
    public class Triangle : BaseGraph
    {
        private float a;
        private float B;
        private float C;
        public Triangle()
        {
            GraphType = E_GraphType.Triangle;
        }

        public Triangle(float a, float b, float c)
        {
            GraphType = E_GraphType.Triangle;
            this.a = a;
            B = b;
            C = c;
        }

        public override float GetArea()
        {
            float temp = GetGirth() / 2;
            return (float)Math.Sqrt(temp * (temp - a) * (temp - B) * (temp - C));
        }

        /*
        public override float GetArea()
        {
            float temp = GetGirth() / 2;
            return (float)Math.Sqrt(temp*(temp-a)*(temp-B)*(temp-C));
        }
        */
        public override float GetGirth()
        {
            return a+B+C;
        }
    }


    public class Circle : BaseGraph
    {
        public override float GetArea()
        {
            throw new NotImplementedException();
        }
    }
}
